﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="OAclient.Common" %>

<script type="text/javascript">
    $(function() {
        $(".datepicker").datepicker();
        $("#searchclrname_wfcurtask").autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: "/Home/SearchUserFormAll",  //要查询的Action
                    type: "POST",  //Post提交
                    dataType: "json", //json格式数据，默认是text
                    data: { keyword: request.term }, //参数，不知道为什么？请指点
                    success: function(data) {
                        response($.map(data, function(item) {
                            return { label: item.text, value: item.value }; //将返回的jsonresult的属性赋值给autocomplete item
                        }))
                    }
                })
            },
            select: function(event, ui) {
                var t = ui.item.label; //'马军 事业部 员工'
                var arr = t.split(' ');
                $('#searchclrname_wfcurtask').val(arr[0]);  //选中item的文本
                $('#searchclrid_wfcurtask').val(ui.item.value); //选中item的值
                return false;
            },
            minLength: '0'
        })


        tableSelectOrder("#wfcurtasklist .table_style");
    });

    function dowfcancel(task_id) {
        if (!confirm("确认要废弃该单据吗？"))
            return false;

        $.ajax({
            type: "POST",
            url: "/WorkFlow/DoWFCancel",
            data: { task_id: task_id },
            success: function(restag) {
                alert(restag.msg);
                $('#menu_worktable').trigger('click');
            }
        });
    }


                                
</script>

<script type="text/javascript">
    $(function() {
        var wfcurtasklistoptions = {
            url: "/WorkFlow/WFCurTaskList",
            type: "POST",
            success: function(data) {
                $("#workarea-2-2").html(data);
            }
        };

        $("#frmwfcurtasklist").ajaxForm(wfcurtasklistoptions);
    })


    function curtaskapproval(uniqueid, task_id, ptask_id) {
        $.ajax({
            type: "POST",
            url: "/WorkFlow/WFProcess",
            data: { "uniqueid": uniqueid, "task_id": task_id, "ptask_id": ptask_id, "str_id": "" },
            success: function(data) {
                addtab('2-2-examine', '审批');
                $("#workarea-2-2-examine").html(data);
            }
        })
    }
</script>

<div id="wfcurtasklist" style="padding-top: 35px;">
    <%using (Html.BeginForm("WFCurTaskList", "WorkFlow", FormMethod.Post, new { id = "frmwfcurtasklist" }))
      {%>
    <div class="selectpanel" style="margin: 5px 20px 5px 70px;">
        审批单名称:
        <%=Html.DropDownList("searchwfname_wfcurtask", ViewData["wfnamelist"] as List<SelectListItem>, "======请选择======", null)%>
        经手人:
        <%=Html.TextBox("searchclrname_wfcurtask")%>
        <%=Html.Hidden("searchclrid_wfcurtask")%>
        时间:
        <%=Html.TextBox("searchstime_wfcurtask", "", new { @class = "datepicker" })%>
        -
        <%=Html.TextBox("searchetime_wfcurtask", "", new { @class = "datepicker" })%>
        <input class="btn_style" type="submit" value="查询" name="submit" />
    </div>
    <div>
        <table border="0" width="100%" class="table_style" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <th class="th_long">
                        审批单名称
                    </th>
                    <th class="th_short">
                        申请人
                    </th>
                    <th class="th_middle">
                        审批状态
                    </th>
                    <th class="th_middle">
                        申请时间
                    </th>
                    <th>
                        备注
                    </th>
                    <th class="th_middle">
                    </th>
                </tr>
            </thead>
            <tbody>
                <%
                    System.Data.DataTable dt_wfworking = ViewData["dt_wfworking"] as System.Data.DataTable;
                    if (dt_wfworking == null || dt_wfworking.Rows.Count == 0)
                    { %>
                <tr>
                    <td colspan="0" style="text-align: center;">
                        当前无数据！
                    </td>
                </tr>
                <%}
                    else
                    {
                        for (int i = 0; i < dt_wfworking.Rows.Count; i++)
                        {
                %>
                <tr>
                    <td>
                        <%=dt_wfworking.Rows[i]["流程名称"]%>
                    </td>
                    <td>
                        <%=dt_wfworking.Rows[i]["发起人"]%>
                    </td>
                    <td>
                        <%=dt_wfworking.Rows[i]["任务名称"]%>
                    </td>
                    <td>
                        <%=DateTime.Parse(dt_wfworking.Rows[i]["开始时间"].ToString()).ToString("yyyy-MM-dd HH:mm")%>
                    </td>
                    <td title='<%=dt_wfworking.Rows[i]["备注"].ToString() %>'>
                        <%=dt_wfworking.Rows[i]["备注"].ToString().Length > 25 ? dt_wfworking.Rows[i]["备注"].ToString().Remove(25) : dt_wfworking.Rows[i]["备注"].ToString()%>
                    </td>
                    <td>
                        <a class="approve" onclick="curtaskapproval('<%=dt_wfworking.Rows[i]["实例标识"] %>',
                        '<%=  dt_wfworking.Rows[i]["任务编码"]%>','<%=dt_wfworking.Rows[i]["父级编码"] %>')">审批</a>
                        <%if (dt_wfworking.Rows[i]["发起人编码"].ToString() == ViewData["user_id"].ToString())
                          { %>
                        <a class="btn_delete" title="废弃" onclick='dowfcancel(<%=dt_wfworking.Rows[i]["任务编码"].ToString() %>)'>
                            废弃</a>
                        <%}
                        %>
                    </td>
                </tr>
                <%
                    }
                    } %>
            </tbody>
        </table>
    </div>
    <div id="pageLink">
        <%var pageInfo = ViewData["pageInfo"] as PagingInfo;%>
        <%if (pageInfo != null)
          {%>
        <%=Ajax.PageLinks(pageInfo, index => Url.Action("WFCurTaskList", new
        {
            page = index,
            wfname = ViewData["searchtaskname_wfcurtask"],
            clrname = ViewData["searchclrname_wfcurtask"],
            stime = ViewData["searchstime_wfcurtask"],
            etime = ViewData["searchetime_wfcurtask"],
        }), new AjaxOptions { UpdateTargetId = "workarea-2-2" })%>
        <%} %>
    </div>
    <%} %>
</div>
